
public class Offer45 {
    public String minNumber(int[] nums) {
        if (nums == null) return "";
        String[] str = new String[nums.length];
        for (int i = 0; i < nums.length; i++) {
            str[i] = String.valueOf(nums[i]);
        }
        quickSort(str, 0, str.length - 1);
        StringBuilder stringBuilder = new StringBuilder();
        for (String s : str) {
            stringBuilder.append(s);
        }
        return stringBuilder.toString();
    }

    public void quickSort(String[] str, int left, int right) {
        if (left >= right) return;
        int l = left;
        int r = right;
        String temp = str[l];
        while (l < r) {
            while ((str[r] + temp).compareTo(temp + str[r]) >= 0 && l < r) r--;
            while ((str[l] + temp).compareTo(temp + str[l]) <= 0 && l < r) l++;
            temp = str[l];
            str[l] = str[r];
            str[r] = temp;
        }
        str[l] = str[left];
        str[left] = temp;
        quickSort(str, left, l - 1);
        quickSort(str, l + 1, right);
    }

}
